﻿@using CQRS.Base.CQRS.Query
@using CQRS.Sales.Interfaces.Presentation
@model PaginatedResult<ProductListItemDto>
           
@{
    ViewBag.Title = "Home Page";

}

<h2>@ViewBag.Message</h2>

<table>
<tr><td style="width:100%;">



<h1>Products available</h1>

    <div class="productsContent">
        <p>Choose from our wide range of quality products</p>
        <div>
        @using (Html.BeginForm())
        {
            <h3>show only products</h3>
            <span>containing text:</span>@Html.TextBox("containsText") <br/>
                
            <span>up to price:</span> @Html.TextBox("maxPrice") <span>EUR <br/></span>
            <a href="#" onclick="document.forms[0].submit(); return false;">Filter</a>
        }
                           
            @Html.ActionLink("Show all", "Index")
        </div>

        
        <p>@Model.TotalItemsCount products found</p>

        <table id="productsTable" class="dataTable">
            <thead>
                <tr>
                    <td class="imageColumn"></td>
                    <td class="productNameColumn sortable">
                        @Html.ActionLink("product name", "Index", new
                                                        {
                                                            sort = "name",
                                                            ascending = !ViewBag.ascending,
                                                            ViewBag.maxPrice,
                                                            ViewBag.containsText,
                                                            ViewBag.pageIndex
                                                        })
                        
                        @if (ViewBag.sort == "name")
                        {
                            if (ViewBag.ascending)
                            {
                                <img src="/Content/sortAscending.png" />
                            }
                            else
                            {
                                <img src="/Content/sortDescending.png" />
                            }
                        }
                                 
                    </td>
                    <td class="priceColumn sortable">@Html.ActionLink("price", "Index", new
                                                 {
                                                     sort = "price",
                                                     ascending = !ViewBag.ascending,
                                                     ViewBag.maxPrice,
                                                     ViewBag.containsText,
                                                     ViewBag.pageIndex
                                                 })
                                 
                        @if (ViewBag.sort == "price")
                        {
                            if (ViewBag.ascending)
                            {
                                <img src="/Content/sortAscending.png" />
                            }
                            else
                            {
                                <img src="/Content/sortDescending.png" />
                            }
                        }
                                 
                    </td>
                    <td class="buttonsColumn"></td>
                </tr>
            </thead>
            <tbody>
                @foreach (var m in @Model.Items)
                {
                    <tr>
                        <td class="imageColumn">
                            <img class="productImage" src="/Content/noProductPicture.png" />
                        </td>
                        <td class="productNameColumn">@m.DisplayedName</td>
                        <td class="priceColumn">@m.Price</td>
                        <td class="buttonsColumn">
                        
                        @using (Html.BeginForm( "Add", "Cart"))
                        {
                            @Html.Hidden("returnUrl", Request.Url.PathAndQuery)
                            <button name="productId" value="@m.ProductId">Add</button>
                        }

                        </td>
                    </tr>
                }
            </tbody>
        </table>

        <div class="paginationContainer">
            @if (@Model.PagesCount > 0)
            {
                <div class="paginationPrompt">jump to page:</div>
                <ul class="pagination">
                    @for (int pageIndex = 0; pageIndex < @Model.PagesCount; pageIndex++)
                    {
                        <li class="@(pageIndex == @Model.PageNumber ? "currentPage" : "")">
                            @Html.ActionLink((pageIndex + 1).ToString(), "Index", new
                       {
                           pageIndex,
                           ViewBag.maxPrice,
                           ViewBag.containsText,
                           ViewBag.sort,
                           ViewBag.ascending

                       })
                        </li>
                    }                                     
                </ul>
            }
        
        </div>
    </div>


</td><td style="border: 0 solid black; vertical-align:top">

    @{ Html.RenderAction("Index", "Cart"); }

</td></tr></table>
